package com.zmn.mcc.common.dto.base;

import com.zmn.common.utils.number.NumberUtil;
import io.swagger.annotations.ApiParam;
import lombok.Data;

import javax.validation.constraints.Max;

/**
 * 描述: 分页查询通用查询类
 *
 * @author guoqiao
 * @since 2021年5月14日
 */
@Data
public class PageQuery {

    @ApiParam(value = "每页条数 (如不填, 默认平台默认条数)")
    @Max(value = 500, message = "单页最大500条")
    private Integer pageSize;

    @ApiParam(value = "页码 （如不填，默认1）")
    private Integer pageIndex;

    @ApiParam(value = "分页起始位置")
    private Integer startIndex;

    public Integer getPageSize() {
        if (NumberUtil.isNullOrZero(this.pageSize)) {
            return 100;
        } else {
            return this.pageSize;
        }
    }

    public Integer getPageIndex() {
        if (NumberUtil.isNullOrZero(this.pageIndex)) {
            return 1;
        } else {
            return this.pageIndex;
        }
    }

    public Integer getStartIndex() {
        int tmpPageIndex = this.getPageIndex() > 0 ? this.getPageIndex() - 1 : 0;
        this.startIndex = tmpPageIndex * this.getPageSize();
        return this.startIndex;
    }

}
